/****
 * Copyright (C) 2006 dNux Team
 *                                                            ****
 * This program is free software; you can redistribute it and/or *
 * modify under the terms of the GNU General Public License as   *
 * published by the Free Software Foundation;                    *
 * either version 2 of the License.                              *
 *                                                               *
 * This program is distributed in the hope that it will be       *
 * useful, but WITHOUT ANY WARRANTY; without even the implied    *
 * warranty of without even the implied waranty of               *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.          *
 * See the GNU General Public License for more details.          *
 *                                                               *
 * You should have received a copy of the                        *
 * GNU General Public License                                    *
 * along with this program; if not, write to the                 *
 * Free Software Foundation, Inc.,                               *
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *
 *                                                               *
 ****                                                         ****/

void
string_new(d_check_t *check)
{
  d_string_t str=NULL;
  str = d_string_new();
  if (!str) {
    d_check_add(check, D_CHECK_ERROR, "string::new => string is NULL");
    goto error;
  }
  d_check_add(check, D_CHECK_OK, "string::new => work");
  d_string_free(&str);
 error:
  return;
}

void
string_free(d_check_t *check)
{
  d_string_t str=NULL;
  
  str = d_string_new();
  if (! str) {
    d_check_add(check, D_CHECK_ERROR, "string::free => d_string_new doesn't work.");
    goto error;
  }
  d_string_free(&str);
  if ( str ) {
    d_check_add(check, D_CHECK_ERROR, "string::free => d_string_free doen't work.");
    goto error;
  }
  
  d_check_add(check, D_CHECK_OK, "string::free => look nice.");
 error:
  return;
}

void
string_add_char(d_check_t *check)
{
  d_string_t string = d_string_new();
  d_string_add_char(&string, 'c');
  if (strcmp(string, "c")) {
    d_check_add(check, D_CHECK_ERROR, "string::add_char => doen't contain 'c'");
    goto error;
  }
  d_string_add_char(&string, 'h');
  if (strcmp(string, "ch")) {
    d_check_add(check, D_CHECK_ERROR, "string::add_char => doen't contain 'ch'");
    goto error;
  }
  d_string_add_char(&string, 'a');
  d_string_add_char(&string, 'r');
  if (strcmp(string, "char")) {
    d_check_add(check, D_CHECK_ERROR, "string::add_char => doen't contain 'char'");
    goto error;
  }

  d_check_add(check, D_CHECK_OK, "string::add_char => contain 'char'");
 error:
  d_string_free(&string);
  return;
}

void
string_add_string(d_check_t *check)
{
  d_string_t str=NULL;
  str = d_string_new();
  d_string_add_string(&str, "str");
  if (strcmp(str, "str")) {
    d_check_add(check, D_CHECK_ERROR, "string::add_string => should equal 'str'");
    goto error;
  }
  d_string_add_string(&str, "ing");
  if (strcmp(str, "string")) {
    d_check_add(check, D_CHECK_ERROR, "string::add_string => should equal 'string'");
    goto error;
  }

  d_check_add(check, D_CHECK_OK, "string::add_string => work great.");
 error:
  d_string_free(&str);
  return;
}

void
string_add_integer(d_check_t *check)
{
  d_string_t str=NULL;
  
  str = d_string_new();
  d_string_add_integer(&str, 12);
  if (strcmp(str, "12")) {
    d_check_add(check, D_CHECK_ERROR, "string::add_integer => str should equal '12'.");
    goto error;
  }
  
  d_string_add_char(&str, 'x');
  d_string_add_integer(&str, 12);
  if (strcmp(str, "12x12")) {
    d_check_add(check, D_CHECK_ERROR, "string::add_integer => str should equal '12x12'");
    goto error;
  }
  
  d_check_add(check, D_CHECK_OK, "string::add_integer => str is okay !");
  
 error:
  d_string_free(&str);
  return;
}

void
string_format(d_check_t *check)
{
  d_string_t str=NULL;
  str = d_string_format("%d: %%%%%s(%c)", 12, "help", 'h');
  
  if (strcmp(str, "12: %%help(h)")) {
    d_check_add(check, D_CHECK_ERROR, "string::format => not good.");
    goto error;
  }
  d_check_add(check, D_CHECK_OK, "string::format => good.");
 error:
  d_string_free(&str);
}

void
string_tests(d_check_t *check)
{
  fprintf(stdout, ">> string_tests <<\n");
  string_new(check);
  string_free(check);
  string_add_char(check);
  string_add_string(check);
  string_add_integer(check);
  string_format(check);
  fprintf(stdout, "\n");
}
